<?php
	class Master{

	function __construct(){
	}

	function __destruct(){
	}

	public static function getVenueDistancesByVenueId($venue_id){
        if(!empty($venue_id)) $where.=" WHERE vd.venue_id =".$venue_id;
        $qry = "SELECT vd.*, cm.name as name FROM venue_distances as vd 
        INNER JOIN city_master as cm ON vd.city_id = cm.id
        ".$where." ORDER BY vd.added ASC";
        
        $rs = MyDB::$db->Execute($qry);

        $venue_distances = array();
        while ($row = $rs->fetchRow()) {
            $venue_distances[] = $row;
        }
        return $venue_distances;
    }
	
	public function getVenueItemList($id=NULL, $active=NULL){
		$where = " WHERE vm.status != '2' ";
		if($id)	$where.=" AND vm.id = ".$id;
		if($active)	$where.=" AND vm.status = '1' ";
		$qry = "SELECT vm.* FROM venue_items_master vm ".$where. " ORDER BY vm.id DESC ";
		
		$rs = MyDB::$db->Execute($qry);
		$venue_item = array();
		while ($row=$rs->fetchRow()) {
			$venue_item[]=$row;
		}
		return $venue_item;
	}
	
	public function getMenuCategoryList($id=NULL, $active=NULL){
		$where = " WHERE mc.status != '2' ";
		if($id)	$where.=" AND mc.id = ".$id;
		if($active)	$where.=" AND mc.status = '1' ";
		$qry = "SELECT mc.* FROM menu_category_master mc ".$where. " ORDER BY mc.id DESC ";
		
		$rs = MyDB::$db->Execute($qry);
		$menu_categories = array();
		while ($row=$rs->fetchRow()) {
			$menu_categories[]=$row;
		}
		return $menu_categories;
	}
	
	public function getActiveServices($id=NULL){
		$status = 1;
		if($id)	$where=" AND sm.id = ".$id;
		$qry = "SELECT sm.id, sm.name,sm
		.attributes FROM services_master as sm
		WHERE sm.status = ".MyDB::$db->qstr($status) . $where;
		$rs = MyDB::$db->Execute($qry);
		$services = array();
		while ($row = $rs->fetchRow()) {
			$services[] = $row;
		}
		return $services;
	}
	
	public function getServices($id=NULL){
		if($id)	$where=" AND sm.id = ".MyDB::$db->qstr($id);
		$qry = "SELECT sm.*, c.name as catname, sc.name as subcatname, ssc.name as subsubcatname 
				FROM services_master as sm
				LEFT JOIN category as c ON c.id = sm.category
				LEFT JOIN category as sc ON sc.id = sm.subcategory
				LEFT JOIN category as ssc ON ssc.id = sm.subsubcategory
				WHERE sm.status != '2' ".$where."
				ORDER BY sm.added DESC";
		$rs = MyDB::$db->Execute($qry);
		$services = array();
		while ($row = $rs->fetchRow()) {
			$services[] = $row;
		}
		return $services;
	}
	
	public function getServicesAttributes($id=NULL){
		$where = " WHERE sa.status != '2' ";
		if($id)	$where.=" AND sa.id = ".$id;
		$qry = "SELECT sa.* FROM services_attributes sa ".$where. " ORDER BY sa.id DESC ";
		
		$rs = MyDB::$db->Execute($qry);
		$attributes = array();
		while ($row=$rs->fetchRow()) {
			$attributes[]=$row;
		}
		return $attributes;
	}
	
	public function getBrandsList($id=NULL, $active=NULL){
		$where = " WHERE b.status != '2' ";
		if($id)	$where.=" AND b.id = ".$id;
		if($active)	$where.=" AND b.status = '1' ";
		$qry = "SELECT b.* FROM brand_master b ".$where. " ORDER BY b.id DESC ";
		
		$rs = MyDB::$db->Execute($qry);
		$brands = array();
		while ($row=$rs->fetchRow()) {
			$brands[]=$row;
		}
		return $brands;
	}
	
	public function getZonesList($id=NULL){
		$where = " WHERE z.status != '2' ";
		if($id)	$where.=" AND z.id = ".$id;
		$qry = "SELECT z.* FROM zone_master z ".$where. " ORDER BY z.id DESC ";
		
		$rs = MyDB::$db->Execute($qry);
		$zones = array();
		while ($row=$rs->fetchRow()) {
			$zones[]=$row;
		}
		return $zones;
	}
	
	public function getCountriesList($id=NULL){
		$where = " WHERE c.status != '2' ";
		if($id)	$where.=" AND c.id = ".$id;
		$qry = "SELECT c.* FROM country_master c ".$where. " ORDER BY c.id DESC ";
		
		$rs = MyDB::$db->Execute($qry);
		$countries = array();
		while ($row=$rs->fetchRow()) {
			$countries[]=$row;
		}
		return $countries;
	}
	
	public function getStatesList($id=NULL){
		$where = " WHERE sm.status != '2' ";
		if($id)	$where.=" AND sm.id = ".$id;
		$qry = "SELECT sm.* , cm.name as country_name
				FROM state_master sm 
				LEFT JOIN country_master cm ON cm.id = sm.country_id
				".$where. " ORDER BY sm.id DESC ";
		
		$rs = MyDB::$db->Execute($qry);
		$states = array();
		while ($row=$rs->fetchRow()) {
			$states[]=$row;
		}
		return $states;
	}
	
	public function getCitiesList($id=NULL){
		$where = " WHERE ctm.status != '2' ";
		if($id)	$where.=" AND ctm.id = ".$id;
		$qry = "SELECT ctm.* , cm.name as country_name,  sm.name as state_name
				FROM city_master ctm 
				LEFT JOIN state_master sm ON ctm.state_id = sm.id
				LEFT JOIN country_master cm ON cm.id = sm.country_id
				".$where. " ORDER BY ctm.id DESC ";
		
		$rs = MyDB::$db->Execute($qry);
		$cities = array();
		while ($row=$rs->fetchRow()) {
			$cities[]=$row;
		}
		return $cities;
	}
    
    public static function getInclusion($sel_id=NULL){
        $status = 1;
        $where = " where status = ". MyDB::$db->qstr($status);        
        $qry = "select * from inclusion_master".$where;
        $rs = MyDB::$db->Execute($qry);
        
        if( $rs ){
            if( is_array($sel_id) ){
                while ($row=$rs->fetchRow()) {
                    $selected = in_array($row['id'], $sel_id) ? 'selected' : '';
                    $option .= '<option value="'.$row['id'].'" '.$selected.'>'.$row['title'].'</option>';
                }
            }else{
                while ($row=$rs->fetchRow()) {
                    $selected = ($row['id'] == $sel_id)?'selected':'';
                    $option .= '<option value="'.$row['id'].'" '.$selected.'>'.$row['title'].'</option>';
                }
            }
        }
        return $option;
    }
}	
?>